package com.rop.znyx.product.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.rop.znyx.common.result.Result;
import com.rop.znyx.model.product.AttrGroup;
import com.rop.znyx.product.service.AttrGroupService;
import com.rop.znyx.vo.product.AttrGroupQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 属性分组 前端控制器
 * </p>
 *
 * @author rop
 * @since 2023-06-24
 */
@Api(tags = "平台属性分组管理")
@RestController
@RequestMapping("admin/product/attrGroup")
@RequiredArgsConstructor

public class AttrGroupController {

    private final AttrGroupService attrGroupService;

    /**
     * 获取平台属性分组列表
     */
    @ApiOperation("获取平台属性分组列表")
    @GetMapping("{page}/{limit}")
    public Result<IPage<AttrGroup>> list(
            @ApiParam(name = "page", value = "当前页数", required = true) @PathVariable Long page,
            @ApiParam(name = "limit", value = "每页条数", required = true) @PathVariable Long limit,
            @ApiParam(name = "attrGroupQueryVo", value = "查询条件") AttrGroupQueryVo attrGroupQueryVo) {

        Page<AttrGroup> pageParam = new Page<>(page, limit);

        IPage<AttrGroup> attrGroupIPage = attrGroupService.selectByPage(pageParam, attrGroupQueryVo);

        return Result.ok(attrGroupIPage);
    }

    /**
     * 根据id获取平台属性分组信息
     */
    @ApiOperation("根据id获取平台属性分组信息")
    @GetMapping("get/{id}")
    public Result<AttrGroup> get(@PathVariable("id") Long id) {
        AttrGroup attrGroup = attrGroupService.getById(id);
        return Result.ok(attrGroup);
    }

    /**
     * 新增平台属性分组
     */
    @ApiOperation(value = "新增平台属性分组")
    @PostMapping("save")
    public Result<Boolean> save(@RequestBody AttrGroup attrGroup) {
        boolean isSuccess = attrGroupService.save(attrGroup);
        return isSuccess ? Result.ok() : Result.fail();
    }

    /**
     * 修改平台属性分组
     */
    @ApiOperation(value = "修改平台属性分组")
    @PutMapping("update")
    public Result<Boolean> updateById(@RequestBody AttrGroup attrGroup) {
        boolean isSuccess = attrGroupService.updateById(attrGroup);
        return isSuccess ? Result.ok() : Result.fail();
    }

    /**
     * 删除平台属性分组
     */
    @ApiOperation(value = "删除平台属性分组")
    @DeleteMapping("remove/{id}")
    public Result<Boolean> remove(@PathVariable Long id) {
        boolean isSuccess = attrGroupService.removeById(id);
        return isSuccess ? Result.ok() : Result.fail();
    }

    /**
     * 根据id列表删除平台属性分组
     */
    @ApiOperation(value = "根据id列表删除平台属性分组")
    @DeleteMapping("batchRemove")
    public Result<Boolean> batchRemove(@RequestBody List<Long> idList) {
        boolean isSuccess = attrGroupService.removeByIds(idList);
        return isSuccess ? Result.ok() : Result.fail();
    }

    /**
     * 获取全部平台属性分组
     */
    @ApiOperation(value = "获取全部平台属性分组")
    @GetMapping("findAllList")
    public Result<List<AttrGroup>> findAllList() {
        return Result.ok(attrGroupService.findAllList());
    }
}

